<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>芯佑电商_会员注册</title>
    <#include "/website/commonWebsite.html">
    <link href="js/checkbox/checkbox.css" rel="stylesheet" type="text/css" />
    <script src="js/checkbox/checkbox.js"></script>
    <!--==本页面白色背景==-->
    <style>
        html{ background: #fff; }
    </style>
</head>
<body>

<!--==页面==-->
<div class="login">
    <!--==头部==-->
    <div class="login-top">
        <h1><a href="#"><img src="/website/images/login_01.png" alt=""></a></h1>
        <ul>
            <li><a href="/website/home">商城首页</a></li>
            <!--<li><a href="#">查找商品</a></li>-->
            <li><a href="/website/login">会员登录</a></li>
        </ul>
    </div>
    <!--==内容==-->
    <div class="login-content">
        <div class="login-content-le"><img src="/website/images/login_02.png" alt=""></div>
        <div class="login-content-ri">
            <h1>会员注册</h1>
            <h2>Membership registration</h2>
            <!--输入框-->
            <div class="login-content-ris">
                <dl>
                    <dt>手机号</dt>
                    <dd><input type="text" id="phone" placeholder="请输入您的手机号码"></dd>
                </dl>
            </div>
            <!--输入框-->
            <div class="login-content-ris">
                <dl class="width">
                    <dt>验证码</dt>
                    <dd class="width"><input type="text" id="validationCode" onblur="checkValidationCode();" placeholder="请输入您的验证码"></dd>
                </dl>
                <button type="button" id="codeid" onclick="getValidationCode();">获取验证码</button>
            </div>
            <div class="login-content-ris">
                <dl>
                    <dt>密码</dt>
                    <dd><input id="password1" type="password" placeholder="请输入密码"></dd>
                </dl>
            </div>
            <div class="login-content-ris">
                <dl>
                    <dt>确认密码</dt>
                    <dd><input id="password2" type="password" placeholder="请输入密码"></dd>
                </dl>
            </div>
            <!--按钮-->
            <div class="login-content-rin"><button type="button" id="register" onclick="register();">确认注册</button></div>
            <!--记住登录-->
            <div class="checklist">
                <!--<label><input type="checkbox" onclick="clickcolor(this);"><span></span>我同意《用户协议》</label>-->
                <p><a href="#">会员登录</a></p>
            </div>
        </div>
    </div>
    <!--== 版权 ==-->
    <div class="login-copyright">
        <span>
            <a href="#">关于我们</a>
            <strong>|</strong>
            <a href="#">免责声明</a>
            <strong>|</strong>
            <a href="#">联系我们</a>
            <strong>|</strong>
            <a href="#">商务合作</a>
            <strong>|</strong>
            <a href="#">售后保障</a>
        </span>
        <p>Copyright © 2019 芯佑电商  沪ICP备1008888号</p>
    </div>
</div>
</body>
<script>
    var countdown=60;
    function settime() {
        if (countdown == 0) {
            $("#codeid").removeAttr("disabled");
            $("#codeid").text("获取验证码");
            countdown = 60;
            return false;
        } else {
            $("#codeid").attr("disabled", "disabled");
            $("#codeid").text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function() {
            settime();
        },1000);
    }

    //获取验证码
    function getValidationCode() {
        var phone = $("#phone").val();
        if (phone != null && phone != "" && phone != "undifiend") {
            $.ajax({
                url : '/register/getVerificationCode',
                type : 'post',
                data : {
                    'telephone' : phone,

                },
                dataType : 'json',
                success : function(resp) {
                    console.log(resp);
                    if (resp.success) {
                        layer.msg("验证码发送成功");
                        settime();
                    } else {
                        layer.msg(resp.message);
                    }
                },
                error : function() {
                    layer.msg("异常错误,请刷新重试");
                }
            });
        }else{
            layer.msg("手机号码不能为空");
        }
    }

    function checkValidationCode() {
        var validationCode = $("#validationCode").val();
        if (validationCode != null && validationCode != "" && validationCode != "undifiend") {
            $.ajax({
                url : '/register/checkValidationCode',
                type : 'post',
                data : {
                    code : validationCode
                },
                dataType : 'json',
                success : function(resp) {
                    if (resp.success) {
                        layer.msg("验证码校验成功");

                    } else {
                        layer.msg(resp.message);
                    }
                },
                error : function() {
                    layer.msg("异常错误,请刷新重试");
                }
            });
        }else{
            layer.msg("验证码不能为空");
        }
    }

    //注册按钮
    function register() {
        //var userType = $("input[name='userType']:checked").val();

        var pass1 = $("#password1").val();
        var pass2 = $("#password2").val();
        var phone = $("#phone").val();
        var code = $("#validationCode").val();

        if (phone == null || phone == "" || phone == "undifiend") {
            layer.msg("手机号码不能为空");
            return;
        }
        else if (code == null || code == "" || code == "undifiend") {
            layer.msg("验证码不能为空");
            return;
        }
        else if (pass1 == "" || pass1 == null || pass1 == "undifiend"||pass2 == "" || pass2 == null || pass2 == "undifiend") {
            layer.msg("密码不能为空");
            return;
        } else if (pass1!=pass2 ) {
            layer.msg("密码不相同");
            return;
        }else {
            $.ajax({
                url : '/register/save',
                type : 'post',
                data : {
                    phone:phone,
                    password1:pass1,
                    password2:pass2,
                    code:code
                },
                dataType : 'json',
                success : function(resp) {
                    if (resp.success) {
                        layer.msg("注册成功");
                        window.location.href = "/website/login";
                    } else {
                        layer.msg(resp.message);
                    }
                },
                error : function() {
                    layer.msg("异常错误,请刷新重试");
                }
            });
        }
    }
</script>
</html>